package com.crois.barrier.common.executor;

import com.crois.barrier.common.factory.BarrierThreadFactory;
import java.util.concurrent.*;

/**
 * @author Hou Ze Yu
 * @description 全局线程池
 * @date 2020/7/7
 */
public class GlobalExecutor {



    private static final long BARRIER_SERVER_HEALTH_CHECK_INTERVAL = TimeUnit.SECONDS.toMillis(60);

    private static final long BARRIER_SERVER_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(6);
    /***
     *线程池公共service
     */
    private static ScheduledExecutorService executorService =
            new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), BarrierThreadFactory.threadCreate("door.task",false));

    public static  void registerServerHealthCheck(Runnable runnable){
        executorService.scheduleAtFixedRate(runnable,BARRIER_SERVER_HEALTH_CHECK_INTERVAL,BARRIER_SERVER_HEALTH_CHECK_INTERVAL, TimeUnit.MILLISECONDS);
    }
}
